package com.gxuwz.controller;

import com.gxuwz.model.entity.Leave;
import com.gxuwz.model.vo.Result;
import com.gxuwz.service.LeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/leave")
public class LeaveController {

    @Autowired
    private LeaveService leaveService;

    // 插入请假记录
    @PostMapping("/add")
    public Result addLeave(@RequestBody Leave leave) {
        int rs = leaveService.addLeave(leave);
        if (rs>0){
            return Result.succeed();
        }else {
            return Result.error("提交失败");
        }
    }


    // 删除请假记录
    @DeleteMapping("/delete/{leaveID}")
    public Result deleteLeaveById(@PathVariable String leaveID) {
        int rs = leaveService.deleteLeaveByID(leaveID);
        if (rs>0){
            return  Result.succeed();
        }else {
            return  Result.error("删除失败");
        }
    }

    // 查询所有请假记录
    @GetMapping("/getAll")
    public Result getAllLeaves() {
        List<Leave> leaves =  leaveService.getAllLeaves();
        return Result.succeed(leaves);
    }
}